define(['base/declare','jquery','widget/Component','base/Data','lib/template','/plugins/bootstrape-select/js/bootstrap-select.js','text!../template/select.template'],
    function (declare,$,Component,Data,template,selectpicker,tpl) {

    return declare([Component],{

        //构造函数
        constructor: function (cfg) {
          //  this.cfg = cfg;
            this.loaded = new $.Deferred();
            this.tplRender = template.compile(tpl);
            var that = this;
            //loaded为异步对象，
            this.loaded.then(function (_d) {
                that._dom = $(that.tplRender($.extend(that.cfg, {data:_d,key:that.cfg.key,val:that.cfg.value})));
            });
        },
        //页面渲染
        renderUI: function(_ctn){
            //加载
            this._loadData();
            //清空容器
            this.container = $(_ctn);
            // this.container.empty();
            var that = this;
            //设置容器和初始数据
            this.loaded.then(function(){
                that.container.append(that._dom);
                that.setValue(that.cfg.value)
            });
        },
        //加载数据
        _loadData: function(){
            var that = this ;
            if(this.cfg.url){
                var _d = $.ajax({
                    url : this.cfg.url,
                    type: this.cfg.type||'GET',
                    dataType : 'json'
                }).then(function (_d) {
                    console.info(_d);
                    that.loaded.resolve(_d);
                });
            }
        },
        //设置数据
        setValue:function(_v){
            this._dom.val(_v);
        },
        //获取数据
        getValue:function(){
            return this._dom.val();
        },
        //验证
        validate: function (_zz) {

        }
    });
});